package com.kocel.block.controller;

import com.alibaba.fastjson.JSON;
import com.kocel.block.model.TbUser;
import com.kocel.block.service.BlockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private BlockService blockService;


    @RequestMapping(value = "/loginApp",produces = "text/html;charset=UTF-8")
    public @ResponseBody
    String loginApp(String userName,String password) {
        Map<String, Object> model = new HashMap<String, Object>();
        TbUser user = blockService.getUser(userName, password);
        if (user==null) {

            model.put("success", false);
            model.put("message", "用户名或密码错误!");
        }
        else {
            model.put("success", true);
            model.put("user", user);
            //model.put("message", "用户名已被注册！");
        }
        String retJson = JSON.toJSONString(model);
        return retJson;
    }
}
